import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
//通过node的path处理这个问题

import path from "path"

let _resolve = (dir) => {
  return path.resolve(dir)
}
export default ({ mode }) => {
  let env = loadEnv(mode, __dirname)

  return defineConfig({
    base: "./",
    plugins: [vue()],
    server: {
      port: 8080,
      proxy: {
        "/api": {
          target: env.VITE_BASE_URL,
          rewrite: path => path.replace(/^\/api/, "")
        }
      }
    },
    build:{
      outDir: path.resolve(env.VITE_MODE)
    },
    resolve: {
      //配置别名
      alias: {
        "@": _resolve('src')
      }
    }
  })
}

